package com.elh.aop.aspect;

import com.elh.aop.model.TimeInterval;

import java.lang.reflect.Method;

/**
 * @author liulei
 **/
public class TimeAspect extends SimpleAspect{

    private TimeInterval timeInterval = new TimeInterval();

    @Override
    public boolean before(Method method, Object target, Object... args) {
        timeInterval.start();
        return true;
    }

    @Override
    public boolean after(Method method, Object target, Object... args) {
        timeInterval.end();
        System.out.println(timeInterval.cost());
        return true;
    }

    @Override
    public boolean throwException(Method method, Object target, Object... args) {
        timeInterval.end();
        return super.throwException(method, target, args);
    }
}
